import React, { lazy } from 'react'
import { Navigate } from 'react-router-dom'
import LayoutBox from '@/layout'
import LazyLoad from './lazyLoad';
import { IRoute } from '@/redux/modules/tag/tag.type';
import { getCache } from '@/utils/session';

export const routerItems: any = (flatRoutes: Array<IRoute>) => {
    // console.log(flatRoutes)
    // console.log(sideRoutes)
    let home =getCache('home');
    let firstPath = '/login';
    if(home){
        firstPath = home.path;
    }
    // debugger
    return [
        {
            path: '',
            element: <Navigate to={firstPath} />
        },
        {
            path: '/',
            element: <LayoutBox />,
            meta: {
                isAuth: true,
            },
            children: (flatRoutes?.length) && [...flatRoutes]
            // children: [...sideRoutes, ...flatRoutes]
        },
        {
            path: '/login',
            element: LazyLoad(lazy(() => import('@/views/login'))),
            meta: {
                isAuth: true,
                title: '登录'
            }
        },
        {
            path: '*',
            element: LazyLoad(lazy(() => import('@/views/error'))),
            meta: {
                isAuth: true,
                title: '404页面'
            }
        },
    ]
}
